
*------------------------------------------------------------------------------*
* Government position of Prime Minister
*
* Additional specs:
*	1. Excluding non-aligned PMs
*	2. Fallback 1: Government position weighted by seats
*	3. Fallback 2: 1st chamber median for expert governments
*
* Version:	2016-06-10
* Changes:	2016-??-??: First release
*------------------------------------------------------------------------------*


* Prime Minister's position excluding non-aligned PMs and those with missing ideological data
gen zs1 = $ideology if p201 == 1 & $ideology !=.
by g101 g105, sort: egen zs2 = max(zs1)


* Fallback 1: Government position weighted by seats
gen filterseat = p303 if p103 == 1 & $ideology != .	// Exclude NONAs and parties with missing ideology
by g101 g105, sort: egen newsumseat=sum(filterseat)	// Estimate new share
gen newpofseat = (filterseat / newsumseat * 100)
gen zs3 = ($ideology * newpofseat) / 100			// Weigh position with new share
by g101 g105, sort: egen zs4 = sum(zs3)				// Aggregate
save zs, replace


* Fill in GOV_POS with fallbacks
gen GOV_POS = zs2
replace GOV_POS = zs4 if GOV_POS == .
replace GOV_POS = median1st if newsumseat == 0 & GOV_POS == 0


* Cleansing
replace GOV_POS = . if g106 == 9

lab var GOV_POS "Position of government"

sort g101 g105 p101

capture: drop zs* filterseat newsumseat newpofseat 
capture: erase zs.dta
capture: erase zs_median.dta
